package event

import (
	"encoding/json"
	"fmt"
	"github.com/vueadmin/app/ws/internal/svc"
	"github.com/vueadmin/pkg/websocket"
)

type Event struct {
	SvcCtx  *svc.ServiceContext
	Ws  	*websocket.Gateway
}

func (p *Event) OnConnect(clientId string) {
	p.Ws.SendToAll(fmt.Sprintf("%s连接成功", clientId))
}

func (p *Event) OnMessage(clientId string, data []byte) {
	var message map[string]interface{}
	if err := json.Unmarshal(data, &message); err != nil {
		fmt.Println("参数错误")
	}
	fmt.Println(message)
}

func (p *Event) OnClose(clientId string) {
	fmt.Println(fmt.Sprintf("%s-断开", clientId))
}
